//
//  RWBalanceGoodsViewCell.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/13.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "RWBalanceGoodsViewCell.h"
#import "ShopCartModel.h"
#import "RWOrderGoodsModel.h"

@interface RWBalanceGoodsViewCell ()

@property (nonatomic, strong) ShopCartModel *shopCartModel;
@property (nonatomic, strong) RWOrderGoodsModel *goodsDetailModel;

@end

@implementation RWBalanceGoodsViewCell

#pragma mark - Init Methods

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setBalanceGoodsUI];
    }
    
    return self;
}

#pragma mark - Load Datas

- (void)loadDataWithModel:(id)model{

    _shopCartModel = [ShopCartModel mj_objectWithKeyValues:model];
    
    [_imageV sd_setImageWithURL:[NSURL URLWithString:_shopCartModel.goods_image] placeholderImage:[UIImage imageNamed:@"huibangke"]];
    _titleLab.text = _shopCartModel.goods_name;
    _moneyLab.text = [NSString stringWithFormat:@"¥ %@", [model objectForKey:@"goods_price"]];
}

- (void)loadDataWithMyOrderDetailModel:(id)model{
    
    _goodsDetailModel = [RWOrderGoodsModel mj_objectWithKeyValues:model];
    
    [_imageV sd_setImageWithURL:[NSURL URLWithString:_goodsDetailModel.goods_image] placeholderImage:[UIImage imageNamed:@"huibangke"]];
    _titleLab.text = _goodsDetailModel.goods_name;
    _moneyLab.text = [NSString stringWithFormat:@"¥ %@", _goodsDetailModel.goods_pay_price];
}

#pragma mark - Config UI

- (void)setBalanceGoodsUI{

    WeakSelf(ws);
    
    UIButton *selectedIcon = [[UIButton alloc] init];
    [self.contentView addSubview:selectedIcon];
    selectedIcon.layer.masksToBounds = YES;
    selectedIcon.layer.cornerRadius = 10.*FTY_WIDTH_BASE;
    [selectedIcon setImage:[UIImage imageNamed:@"selected_icon"] forState:UIControlStateNormal];
    [selectedIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.mas_centerY);
        make.left.mas_equalTo(15.*FTY_WIDTH_BASE);
        make.width.height.mas_equalTo(20.*FTY_WIDTH_BASE);
    }];
    
    UIImageView *imageV = [[UIImageView alloc] init];
    [self.contentView addSubview:imageV];
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.mas_centerY);
        make.left.mas_equalTo(selectedIcon.mas_right).offset(10.*FTY_WIDTH_BASE);
        make.width.height.mas_equalTo(60.*FTY_WIDTH_BASE);
    }];
    _imageV = imageV;
    
    UILabel *titleLab = [[UILabel alloc] init];
    [self.contentView addSubview:titleLab];
    titleLab.textColor = [UIColor blackColor];
    titleLab.font = FTY_FONTTSIZE(14);
    titleLab.numberOfLines = 3;
    [titleLab sizeToFit];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(20.*FTY_HEIGHT_BASE);
        make.left.mas_equalTo(imageV.mas_right).offset(25.*FTY_WIDTH_BASE);
        make.right.mas_offset(-12.*FTY_WIDTH_BASE);
    }];
    _titleLab = titleLab;
    
    UILabel *moneyLab = [[UILabel alloc] init];
    [self.contentView addSubview:moneyLab];
    moneyLab.textColor = [FTYColor getMainColorWithAlpha:1.];
    moneyLab.font = FTY_FONTTSIZE(15);
    [moneyLab sizeToFit];
    [moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLab.mas_bottom).offset(10.*FTY_HEIGHT_BASE);
        make.left.mas_equalTo(titleLab.mas_left);
    }];
    _moneyLab = moneyLab;
    
    //底部线
    UIView *bottomLine = [[UIView alloc] init];
    [self.contentView addSubview:bottomLine];
    bottomLine.backgroundColor = [FTYColor grayColor];
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(.5*FTY_HEIGHT_BASE);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
